package com.itany.utils;

import com.itany.crawler.Main;
import com.itany.crawler.Urls;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Date;
import java.util.UUID;

public class Log {


    public static void logErr(Iterable<? extends CharSequence> lines) {
        try {
            Files.write(Paths.get(Main.testDataPath, "err.txt"), lines, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void logErr(byte[] bytes) {
        try {
            Files.write(Paths.get(Main.testDataPath, "err.txt"), bytes, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void logErr(String line) {
        byte[] bytes = (new Date() + " : " + line + "\n").getBytes();
        try {
            Files.write(Paths.get(Main.testDataPath, "err.txt"), bytes, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void logHtml(String fileName, String line) {
        try {
            Files.write(Paths.get(Main.testDataPath, fileName), line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void logLines(String filename, String line) {
        line = line + "\n";
        try {
            Files.write(Paths.get(Main.testDataPath, Urls.file), line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void saveUrl(String line) {
        logLines(Urls.file, line);
    }






}
